import { useRequest } from "ahooks";
import { message } from "antd";
import Https from "./Https";

export default function useRequests(service, options = {}) {
  return useRequest(service, {
    ...options,
    requestMethod: (params) => {
      const { method } = params;
      if (method === "get") {
        params.params = params.data;
      }
      return Https(params);
    },
    throwOnError: true,
    onError: (error) => {
      message.destroy();
      message.error(error.message);
    },
  });
}
